package ext.generic.project.reports.validator;





import java.util.Locale;

import wt.fc.WTReference;
import wt.org.WTUser;
import wt.session.SessionHelper;
import wt.util.WTException;
import wt.util.WTProperties;

import com.ptc.core.ui.validation.DefaultUIComponentValidator;
import com.ptc.core.ui.validation.UIValidationCriteria;
import com.ptc.core.ui.validation.UIValidationKey;
import com.ptc.core.ui.validation.UIValidationResult;
import com.ptc.core.ui.validation.UIValidationResultSet;
import com.ptc.core.ui.validation.UIValidationStatus;
import com.ptc.projectmanagement.plan.PlanActivity;

/**
 * 用于过滤 阶段文件齐套性检查入口
 * @author John
 *
 */
public class PhaseReviewDocumentsValidator  extends DefaultUIComponentValidator {
	private static boolean VERBOSE=true;
	private static Locale locale=null;
	private static String CLASSNAME = PhaseReviewDocumentsValidator.class.getName();

	static {
		try {
			VERBOSE= (WTProperties.getLocalProperties()).getProperty("ext.generic.project.reports.verbose", true);
			locale=SessionHelper.manager.getLocale();
		} catch (Throwable throwable) {
			throw new ExceptionInInitializerError(throwable);
		}
	}
	

	public UIValidationResultSet performFullPreValidation(UIValidationKey validationkey, UIValidationCriteria validationcriteria, Locale locale)
	throws WTException {
		if (VERBOSE) {
			System.out.println(">>>>>>"+CLASSNAME+">>>>performFullPreValidation()");
		}
		WTUser curUser =(WTUser)SessionHelper.manager.getPrincipal();
		UIValidationResultSet resultSet = new UIValidationResultSet();
		WTReference wtreference = validationcriteria.getContextObject();
		if (wtreference == null) {
			if (VERBOSE){
				System.out.println("wtreference*==null*>>>");
				
			}
			resultSet.addResult(new UIValidationResult(validationkey, UIValidationStatus.HIDDEN));
		}
		if(wtreference.getObject() instanceof PlanActivity){
			PlanActivity activity=(PlanActivity) wtreference.getObject();
			
			if(activity.isMilestone()){
				//是里程碑
				if (VERBOSE){
					System.out.println("the activity:"+activity.getName()+" is Milestone(),need Enabled ");
				}
				resultSet.addResult(UIValidationResult.newInstance(validationkey, UIValidationStatus.ENABLED));
				
			}else{
				//非里程碑
				resultSet.addResult(UIValidationResult.newInstance(validationkey, UIValidationStatus.HIDDEN));
			}
		}else{
			resultSet.addResult(UIValidationResult.newInstance(validationkey, UIValidationStatus.HIDDEN));
			
		}
		
		return resultSet;

	}
}
